<%-- 
    Document   : register
    Created on : May 4, 2011, 12:11:49 PM
    Author     : Administrator
--%>

<%@page import="java.util.Date"%>
<%@page import="entitys.Users"%>
<%@page import="session.UsersFacadeRemote"%>
<%@page import="javax.naming.InitialContext"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<%
try{
    String sa = request.getParameter("command");
int uid =0; 
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Page</title>

    </head>
    <body>
       <%  if (sa==null) {%>
        <h1>&nbsp;</h1>

        <form action="register.jsp">
            <table width="279" height="212" border="2" cellpadding="1" cellspacing="1">
                <thead>
                    <tr>
                        <th > User Registration </th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>First Name </td>
                        <td><input type="text" name="fname" value="" /></td>
                    </tr>
                    <tr>
                        <td>Last Name</td>
                        <td><input type="text" name="lname" value="" /></td>
                    </tr>
                    <tr>
                        <td>Birth Date</td>
                        <td><input type="text" name="bdate" value="" /></td>
                    </tr>
                    <tr>
                        <td>Gender</td>
                        <td><select name="gender">
                                <option>Male</option>
                                <option>Female</option>
                            </select></td>
                    </tr>
                    <tr>
                        <td>E-Mail</td>
                        <td><input type="text" name="email" value="" /></td>
                    </tr>
                    <tr>
                        <td>User Name</td>
                        <td><input type="text" name="un" value="" /></td>
                    </tr>
                    <tr>
                        <td>Password</td>
                        <td><input type="text" name="pw" value="" /></td>
                    </tr>
                    <tr>
                        <td height="20"><input type="submit" name="sub" value="Register" /></td>
                <input type="hidden" name="command" value="Register" />

                <td><input type="reset" name="res" value="Clear" /></td>
                </tr>
                </tbody>
            </table>
        </form>
        <% } 
else

{

           if (sa.equalsIgnoreCase("register")) {

                    String fname = request.getParameter("fname");
                    String lname = request.getParameter("lname");
                    String email = request.getParameter("email");
                    String bd = request.getParameter("bdate");
                    String un = request.getParameter("un");
                    String pw = request.getParameter("pw");
                    String gender = request.getParameter("gender");

                    InitialContext c = new InitialContext();
                    UsersFacadeRemote userFacade = (session.UsersFacadeRemote) c.lookup("session.UsersFacadeRemote");
System.out.println(userFacade);
                    Users u = new Users();
                    
                    u.setFName(fname);
                    u.setLName(lname);
                    u.setBDate(new Date(bd));
                    u.setGender(gender);
                    u.setEMail(email);
                    u.setPw(pw);
                    u.setUn(un);
                    u =  userFacade.create1(u);
                    System.out.println(u.getId());
                    uid = u.getId() ; 
                    %>
        <a href="index.jsp">Please Login you are <%=uid%> user </a>
        <%
                    
                    
                }

}      

}catch(Exception e){

e.printStackTrace();

}    %>


 
 
    </body>
</html>
